package openc.ui.demo;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import openc.ui.JWindowsListBar;

public class WindowsListBarDemo extends JFrame implements ActionListener {
    public WindowsListBarDemo() {
        super("Демо JFrameListBar");

        count = 0;
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new BorderLayout());

        JMenuBar menuBar = new JMenuBar();
        JMenu windowMenu = new JMenu("Окна");
        JMenuItem newItem = new JMenuItem("Новое окно");
        newItem.addActionListener(this);
        windowMenu.add(newItem);
        menuBar.add(windowMenu);
        setJMenuBar(menuBar);

        desktop = new JDesktopPane();
        add(desktop, BorderLayout.CENTER);

        newWindow("Test 0");

        windowsBar = new JWindowsListBar(desktop);
        add(windowsBar, BorderLayout.SOUTH);

        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        count++;
        newWindow("Window " + count);
    }

    private void newWindow(String title) {
        JInternalFrame window = new JInternalFrame(title, true, true, true, true);
        window.setSize(200, 200);
        desktop.add(window);
        window.setVisible(true);
    }

    private JDesktopPane desktop;
    private JWindowsListBar windowsBar;
    int count;
}